package com.szrt.java.day20170109.demo03;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class ArrayListTest03 {

	static List<Student> studentList = new ArrayList<Student>();
	
	public static void main(String[] args) {
		
		Student lyh = new Student();
		lyh.setName("刘宇宏");
		lyh.setPhoneNum("15989309781");
		lyh.setAge(24);
		
		Student lh = new Student();
		lh.setName("刘浩");
		lh.setAge(24);
		lh.setPhoneNum("110");
		
		studentList.add(lyh);
		studentList.add(lh);
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("请输入要修改信息的同学的姓名：");
		String findName = sc.next();
		
		System.out.println("请输入需改后的电话号码：");
		String cPhoneNum = sc.next();
		
		System.out.println("请输入要修改后的年龄：");
		int cAge = sc.nextInt();
		
		sc.close();
		
		System.out.println("修改前================================================");
		for(Student s:studentList){
			System.out.println(s.toString());
		}
		
		
		
		changeStudent(findName,cPhoneNum,cAge);
		
		
	}
	
	/**
	 * 
	 * @param name
	 * @param newPhone
	 * @param newAge
	 * @param stu
	 */
	public static void changeStudent(String name,String newPhone,int newAge){
		
		for(int i =0;i<studentList.size();i++){
			
			Student stu = studentList.get(i);
			String temp = stu.getName();
			
			if(name.equals(temp)){
				stu.setAge(newAge);
				stu.setPhoneNum(newPhone);
				System.out.println("修改后================================================");
				for(Student s:studentList){
					System.out.println(s.toString());
				}
				break;
			}
			
		}
	}
}
